<extend name="Public/base"/>


<block name="body">
<div class="row">
<div class="col-md-12">
<div class="portlet box blue">
<div class="portlet-title">
<div class="caption"><i class="fa fa-reorder"></i>添加学生信息</div>
<div class="tools">
    <a href="javascript:;" class="collapse"></a>
    <a href="javascript:;" class="remove"></a>
</div>
</div>
<div class="portlet-body form">
<form class="form-horizontal add_sutdent" action="{:U('')}" method="post">
    <div class="form-body">
        <div class="col-md-6">
            <div class="form-group">
                <label class="control-label col-md-3">姓名</label>
                <div class="col-md-6">
                    <input type="text" name="username" value="<if condition='$userinfo.username neq null'>{$userinfo.username}</if>" class="form-control" placeholder="请输入真实姓名"/>
                </div>
            </div>
            <div class="form-group">
                <label class="control-label col-md-3">学号</label>
                <div class="col-md-6">
                    <input name="student_number" value="<if condition='$userinfo.student_number neq null'>{$userinfo.student_number}</if>" type="text" class="form-control"/>
                </div>
            </div>
            <empty name="userinfo">
                <div class="form-group">
                    <label class="control-label col-md-3">默认密码</label>
                    <div class="col-md-6">
                        <input name="password" type="text" value="12345678" class="form-control" />
                    </div>
                </div>

            </empty>

            <div class="form-group">
                <label class="control-label col-md-3">性别</label>
                <div class="col-md-5">
                    <div class="radio-list">

                        <if condition="$userinfo.sex eq 1">
                            <label class="radio-inline">
                                <input name="sex" type="radio" value="0" >男
                            </label>
                            <label class="radio-inline">
                                <input name="sex" type="radio" value="1" checked >女
                            </label>
                            <else/>
                            <label class="radio-inline">
                                <input name="sex" type="radio" value="0" checked>男
                            </label>
                            <label class="radio-inline">
                                <input name="sex" type="radio" value="1">女
                            </label>
                        </if>


                    </div>
                </div>
            </div>
            <div class="form-group">
                <label class="control-label col-md-3">所在年级</label>
                <div class="col-md-6">
                    <select name="gid" onchange="gradeCheck(this.value)" class="form-control input-medium">
                        <option value="">请选择</option>
                        <volist name="class_list" id="vo">
                            <if condition="$userinfo.gid eq $vo.gid ">
                                <option value="{$vo.gid}" selected="selected">{$vo.class_name}</option>
                                <else/>
                                <option value="{$vo.gid}">{$vo.class_name}</option>
                            </if>
                        </volist>
                    </select>
                </div>
            </div>
            <noempty>
                <input type="hidden" value="{$userinfo.stid}" name="stid"/>
            </noempty>
            <div class="form-group">
                <label class="control-label col-md-3">所在班级</label>
                <div class="col-md-6">
                    <select name="cid" class="form-control input-medium">
                        <option>请选择</option>
                        <noempty>
                            <volist name="class_info" id="vs">
                                <if condition="$userinfo.cid eq $vs.id ">
                                    <option value="{$vs.id}" selected="selected">{$vs.grade_name}</option>
                                    <else/>
                                    <option value="{$vs.id}">{$vs.grade_name}</option>
                                </if>
                            </volist>
                        </noempty>
                    </select>
                </div>
            </div>
            <div class="form-group">
                <label class="control-label col-md-3">监护人</label>
                <div class="col-md-6">
                    <input name="guardian" value="<if condition='$userinfo.guardian neq null'>{$userinfo.guardian}</if>" type="text" class="form-control" placeholder="请输入监护人姓名"/>
                </div>
            </div>

            <div class="form-group">
                <label class="control-label col-md-3">监护人电话</label>
                <div class="col-md-6">
                    <input type="text" value="<if condition='$userinfo.guardian_tel neq null'>{$userinfo.guardian_tel}</if>" name="guardian_tel" class="form-control" placeholder="请输入监护人电话号码"/>
                </div>
            </div>
        </div>
        <div class="col-md-6">
            <div class="form-group">
                <label class="control-label col-md-4">头像照片</label>
                <div class="col-md-8">
                    <div class="fileupload fileupload-new" data-provides="fileupload">
                        <div class="fileupload-new thumbnail" >
                            <img id="field_pic_headimg" style="width:120px;height: 160px;" src="{$userinfo.headimg}" alt="" />
                        </div>
                        <div class="fileupload-preview fileupload-exists thumbnail" style="max-width: 150px; max-height: 200px; line-height: 20px;"></div>
                        <div>
                            <input type="file"  class="default"  id="headimg"    />
                            <input type="hidden"  name="headimg"   value="{$userinfo.headimg}" />

                        </div>
                    </div>
                </div>
            </div>

            <div class="form-group">
                <label class="control-label col-md-3">身份证号码</label>
                <div class="col-md-6">
                    <input name="idcard" value="<if condition='$userinfo.idcard neq null'>{$userinfo.idcard}</if>" type="text" class="form-control" placeholder="请输入身份证号码"/>
                </div>
            </div>
            <div class="form-group">
                <label class="control-label col-md-3">现居住地</label>
                <div class="col-md-6">
                    <input name="residence" value="<if condition='$userinfo.residence neq null'>{$userinfo.residence}</if>" type="text" class="form-control" placeholder="请输入现居住地址"/>
                </div>
            </div>

            <div class="form-group">
                <label class="control-label col-md-3">入学说明</label>
                <div class="col-md-6">
                    <textarea rows="3" name="enter_state"  type="text" class="form-control" placeholder="请输入说明内容"><if condition="$userinfo.enter_state neq null">{$userinfo.enter_state}</if></textarea>
                </div>
            </div>

        </div>




        <div class="clearfix"></div>
    </div>
    <div class="form-actions fluid">
        <div class="row">
            <div class="col-md-12">
                <div class="col-md-offset-3 col-md-6">
                    <button type="submit" target-form="add_sutdent" class="ajax-post btn green">确定</button>
                    <button type="button" onclick="javascript:history.back(-1);return false;" class="btn default">返回</button>
                </div>
            </div>
        </div>

    </div>

</form>
<div class="clearfix"></div>
</div>
</div>
<!-- END PORTLET-->
</div>
</div>

</block>

<block name="script">

<!-- END PAGE LEVEL PLUGINS -->
<!-- BEGIN PAGE LEVEL SCRIPTS -->
<script src="__STATIC__/scripts/app.js"></script>
<script src="__STATIC__/scripts/table-managed.js"></script>
<script type="text/javascript" src="__STATIC__/uploadify/jquery.uploadify.min.js?t={:rand(0,9999)}"></script>
<script>
    var _file = []; _file['picture'] = [];
    _file['picture'].push("headimg");


jQuery(document).ready(function() {
App.init();
TableManaged.init();
highlight_subnav('{:U('User/studentList')}');

    _file['picture'].forEach(function(i){
        $("#"+i).uploadify({
            "height"          : 34,
            "swf"             : "__STATIC__/uploadify/uploadify.swf",
            "fileObjName"     : "download",
            "buttonText"      : "上传图片",
            "uploader"        : "{:U('File/uploadPicture',array('session_id'=>session_id()))}",
            "width"           : 80,
            'removeTimeout'	  : 1,
            'fileTypeExts'	  : '*.jpg; *.png; *.gif;',
            "onUploadSuccess" : function(file, data){
                var data = $.parseJSON(data);
                var src = '';
                console.log(data);
                if(data.status){
                    $("input[name='"+i+"']").val(data.path);
                    src = data.url || '__ROOT__' + data.path
                    $("#field_pic_"+i).attr({"src":src}).parent().css({"width":'',"height":''});
                } else {
                    updateAlert(data.info);
                    setTimeout(function(){
                        $('#top-alert').find('button').click();
                        $(that).removeClass('disabled').prop('disabled',false);
                    },1500);
                }
            },
            'onFallback' : function() {
                alert('未检测到兼容版本的Flash.');
            }
        });
    })
});

    function gradeCheck(gid){
        var txt="<option value=''>请选择</option>";
        $.post("{:U('Public/classInfo')}",{gid:gid},function(data){
            $.each(data,function(k,v){
                txt+= "<option value='"+ v.id +"'>" + v.grade_name + "</option>";
            });
            $("[name='cid']").html(txt);
        })
    }

</script>
</block>